package cn.flying.cloud.core.auth.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @description: httpSession 监听实现类  监听器注册可以用过注解@WebListener，也可以通过ServletListenerRegistrationBean注入，
 * @author: admin
 * @date: 2023年06月05日 19:10
 * @version: 1.0
 */
@WebListener
public class CustomHttpSessionListener implements HttpSessionListener {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void sessionCreated(HttpSessionEvent event) {
        HttpSession session = event.getSession();
        String id = session.getId();
        logger.info("session创建了，sessionId：【{}】", id);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        HttpSession session = event.getSession();
        String id = session.getId();
        logger.info("session销毁了，sessionId：【{}】", id);
    }
}
